package com.zy.view.study;

import android.content.Context;
import android.graphics.Canvas;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.widget.Button;

import com.zy.zlog.ZLog;

public class DiyButtonC extends Button {

    private static final String TAG = "DiyButtonC";

    public DiyButtonC(Context context) {
        super(context);
    }

    public DiyButtonC(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public DiyButtonC(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    public DiyButtonC(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        ZLog.d(TAG, "widthMeasureSpec:" + MeasureSpec.toString(widthMeasureSpec) + " heightMeasureSpec:" + MeasureSpec.toString(heightMeasureSpec));
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    }

    @Override
    protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
        ZLog.d(TAG, "onLayout s 测量宽高:[" + getMeasuredWidth() + "," + getMeasuredHeight() + "] 实际宽高[" + getWidth() + "," + getHeight() + "] " + "[" + left + "," + top + "," + right + "," + bottom + "]");
        //ZLog.d(TAG, "onLayout s :[" + left + "," + top + "," + right + "," + bottom + "]");
        super.onLayout(changed, left, top, right, bottom);
        //ZLog.d(TAG, "onLayout e 测量宽高:[" + getMeasuredWidth() + "," + getMeasuredHeight() + "] 实际宽高[" + getWidth() + "," + getHeight() + "]");
    }

    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
        ZLog.d(TAG, "------dispatchTouchEvent start " + MotionEvent.actionToString(ev.getAction()));
        boolean dispatch = super.dispatchTouchEvent(ev);
        ZLog.d(TAG, "-----dispatchTouchEvent end " + MotionEvent.actionToString(ev.getAction()) + " dispatch:" + dispatch);
        return dispatch;
    }

    @Override
    public boolean onTouchEvent(MotionEvent ev) {
        ZLog.d(TAG, "--------onTouchEvent start " + MotionEvent.actionToString(ev.getAction()));
        boolean touch = super.onTouchEvent(ev);
        ZLog.d(TAG, "--------onTouchEvent end " + MotionEvent.actionToString(ev.getAction()) + " touch:" + touch);
        return touch;
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
    }
}
